<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<link rel="stylesheet" type="text/css" href="css/common.css"/>
		<link rel="stylesheet" type="text/css" href="css/lawyer_list.css"/>
	</head>
	<body>
		<form action="" method="post" id="form" class="search_box">
			<span>姓名：<input type="text" id="name" name="name"/></span>
			<span>手机号：<input type="text" id="mobile" name="mobile"/></span>
			<span>执业证号：<input type="text" id="cert" name="cert"/></span>
			<span>擅长领域：
				<select name="expert" id="expert">
					<option value="">全部</option>
					<option value="婚姻继承">婚姻继承</option>
					<option value="合同纠纷">合同纠纷</option>
					<option value="民间借贷">民间借贷</option>
					<option value="人身损害">人身损害</option>
					<option value="房产纠纷">房产纠纷</option>
					<option value="建筑拆迁">建筑拆迁</option>

					<option value="刑事辩护">刑事辩护</option>
					<option value="行政案件">行政案件</option>
					<option value="知识产权">知识产权</option>
					<option value="公司法务">公司法务</option>
					<option value="劳动争议">劳动争议</option>
					<option value="专业打假">专业打假</option>

					<option value="税务律师">税务律师</option>
					<option value="金融纠纷">金融纠纷</option>
					<option value="交通事故">交通事故</option>
				</select>
			</span>
				
			<button type="button" class="sub">搜索</button>
		</form>

			<div id="list_content">

			</div>

		<div class="tcdPageCode"></div>
		<script src="js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript" src="layui/layui.js"></script>
		<script src="js/jquery.page.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/jquery.cookie.js" type="text/javascript" charset="utf-8"></script>
		<script>
		jQuery.browser={};(function(){jQuery.browser.msie=false; jQuery.browser.version=0;if(navigator.userAgent.match(/MSIE ([0-9]+)./)){ jQuery.browser.msie=true;jQuery.browser.version=RegExp.$1;}})();

		var params={
				name:'',//姓名
				mobile:'',//手机号
				cert:'',//执业证号
				expert:'',//领域
				limit:20 ,//记录数
				offset:1//页码
			 };
			$(document).ready(function() {

				search(true);//搜索

				//绑定搜索事件
				$(".sub").click(function(){
					params.name=$("#name").val();
					params.mobile=$("#mobile").val();
					params.cert=$("#cert").val();
					params.expert=$("#expert").val();
					params.offset = 1;
					search(true);
				});
			});

			document.onkeydown = function(event){
				var e = event || window.event || arguments.callee.caller.arguments[0];
				if(e && e.keyCode == 116){
					event.preventDefault();
					
					$(window.parent.$('.showIframe').each(function(){
						if(!$(this).hasClass('hideIframe')){
							$(this).children('iframe').attr('src',$(this).children('iframe').attr('src'))
						}
					}))
				}
			}

			//删除方法
			function del(id){
				$.ajax({
					url: 'lawyer/'+id,
					type: 'delete',
					dataType: "json",
					success: function (data) {
						if(data.rel){
//							alert("删除成功");
							layui.use('layer', function() {
								var layer = layui.layer;
								layer.msg('删除成功', {
									icon: 6
								})
							})
							search(false);
						}
					}
				});
			}
			//查询方法
			function search(flag){

				$.ajax({
						 url: 'lawyer/list',
						 type: 'get',
						 data:params,
						 dataType: "json",
						 success: function (data) {
						    var headTable="<table border='0' cellspacing='0' cellpadding='0'><tr><th>ID</th><th>头像</th><th>姓名</th>"
						    +"<th>手机号</th><th>执业证号</th><th>微信二维码</th><th>擅长领域</th><th>操作</th></tr>";
						    var contentHtml="";
								if(data.rows.length > 0){
								  var reg=new RegExp(",","g");
									for(var i=0;i<data.rows.length;i++){
											var obj=data.rows[i];
											var index=i+1;
											//var expert=obj.expert.replace(reg,"</span> / <span>");
											contentHtml+="<tr><td>"+obj.id+"</td><td><img src='"+obj.imgpic+"'/></td>"
						 		              +"<td>"+obj.name+"</td><td>"+obj.mobile+"</td><td>"+obj.cert+"</td>"
						 		              +"<td><img src='"+obj.weixin+"' ></td>"
						 		              
						 		              +"<td><button id='" + obj.id + "' class='edit'>编辑</button><button id='"+obj.id+"' class='del'>删除</button></td>	</tr>";
						    	}
								}else{
									contentHtml="<tr><td colspan='8'>暂无记录</td></tr>";
									$(".tcdPageCode").createPage({
											pageCount:1,
											current:1,
											backFn:function(p){

											}
									});
								}


								$("#list_content").html(headTable+contentHtml+"</table>");

								//绑定edit事件
						$(".edit").click(function() {

							var id = $(this).attr("id");
								edit(id);

						});
								//绑定删除事件
								$(".del").click( function(){
									var id = $(this).attr("id");
									layui.use('layer', function() {
										var layer = layui.layer;
										layer.confirm('确认删除此信息', {icon: 3},function(index){
											layer.close(index)
											del(id);
										},function(index){
											layer.close(index)
										})
									})
								});
								if(flag && data.rows.length > 0){
									$('.tcdPageCode').off('click');
									$(".tcdPageCode").createPage({
											pageCount:data.totalPages,
											current:data.page,
											backFn:function(p){
													//console.log(p);
													params.offset=p;
													search(false);
											}
									});
								}
						 }
     		});
			}

				//编辑方法
			function edit(id) {
			  $.cookie("articleId",id, { expires: 1 });
				 var text = "添加律师";
					$(window.parent.$(".acrossTab li").each(function() {
							if ($(this).children('span').text() == text) {
									$(window.parent.$("aside").attr('data-tip', 1));
									$(this).click();
							} else {
									$(window.parent.$("aside li").each(function() {
											if ($(this).text() == text) {
													$(this).click();
											}
									}));
							}
					}));
			}
		</script>
	</body>
</html>
